clear all
clc
% n = input('number of classes: ');
muc=0.033;
C=40;
Lambdac= 2:0.1:15 ;
T=5;
R=zeros(length(Lambdac),1);
Waitings=zeros(length(Lambdac),1);
numbers=zeros(length(Lambdac),1);

for j=1:length(Lambdac)
n=ceil(((Lambdac(j) - muc)*T)/(T*C*muc-1));
%  n=14;
numbers(j)= n;
% Pv=Gaussiandist(n);
Pv=decreasingdist(n);
Pc=Gaussiandist(n);
lb=zeros(n,1);
ub=ones(n,1);
ub(n+1)=inf;
b1=zeros(n+2,1);
lb(n+1)=Lambdac(j) + n*(1/T) ;
for i=1:n
    b1(i)= Lambdac(j)*Pc(i) + (1/T) ;
end
b1(n+1)= -C*n*muc;
b1(n+2)= -muc;
cond = @(x)parameterfun(x,n,Pv,b1);
obj=@(x)x(n+1);
x0 = ones(1,n);
x0(n+1)= Lambdac(j);
[x,fval,exitflag,output,lambda] = fmincon(obj,x0,[],[],[],[],lb,ub,cond);
R(j)= x(n+1);
[cout,ceqout] = parameterfun(x,n,Pv,b1);
Waitings(j)=max(1/(-cout(1:n)+0.1));
end

plot(Lambdac,R);
hold on
% figure;
% plot(T,Waitings);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% clear all
% clc
% % n = input('number of classes: ');
% muc=0.033;
% C=40;
% Lambdac= 2:0.1:15 ;
% T=10;
% R=zeros(length(Lambdac),1);
% Waitings=zeros(length(Lambdac),1);
% numbers=zeros(length(Lambdac),1);
% 
% for j=1:length(Lambdac)
% n=ceil(((max(Lambdac) - muc)*T)/(T*C*muc-1));
% numbers(j)= n;
% Pv=Gaussiandist(n);
% Pc=Gaussiandist(n);
% lb=zeros(n,1);
% ub=ones(n,1);
% ub(n+1)=inf;
% b1=zeros(n+2,1);
% lb(n+1)=Lambdac(j) + n*(1/T) ;
% for i=1:n
%     b1(i)= Lambdac(j)*Pc(i) + (1/T) ;
% end
% b1(n+1)= -C*n*muc;
% b1(n+2)= -muc;
% cond = @(x)parameterfun(x,n,Pv,b1);
% obj=@(x)x(n+1);
% x0 = ones(1,n);
% x0(n+1)= Lambdac(j);
% [x,fval,exitflag,output,lambda] = fmincon(obj,x0,[],[],[],[],lb,ub,cond);
% R(j)= x(n+1);
% [cout,ceqout] = parameterfun(x,n,Pv,b1);
% Waitings(j)=max(1/(-cout(1:n)+0.1));
% end
% 
% plot(Lambdac,R);
% hold on
% figure;
% plot(T,Waitings);

